﻿namespace HRM.CORE.Workdesk.Chart
{
    using DevExpress.XtraCharts;
    using DevExpress.XtraCharts.Printing;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using Microsoft.VisualBasic;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using Common.Report;
    using HRM.CORE;
    using HRM.CORE.REPORT;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms; using Common;
    using Common;

    public class xucChartSalary : Common.xucBase
    {
        private ChartControl chartSalary;
        private Common.Class.clsAllOption clsAllOption = new Common.Class.clsAllOption();
        private IContainer components = null;
        private TimeEdit dtFromDate;
        private TimeEdit dtToDate;
        private LabelControl labelControl1;
        private LabelControl labelControl2;
        private LinkLabel lbPrintAge;
        private LinkLabel llRefresh;
        private PanelControl panelControl1;
        private PanelControl panelControl3;

        public xucChartSalary()
        {
            this.InitializeComponent();
            this.InitComponent();
            this.LoadChartSalary();
        }

        private void ChartPrint_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            xfmReport report = new xfmReport("Biểu Đồ");
            rptChartSalary xtraReport = new rptChartSalary(System.DateTime.Parse(this.dtFromDate.EditValue.ToString()), System.DateTime.Parse(this.dtToDate.EditValue.ToString()));
            report.ShowPrintPreview(xtraReport);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void dtFromDate_EditValueChanged(object sender, EventArgs e)
        {
            this.LoadChartSalary();
        }

        private void dtToDate_EditValueChanged(object sender, EventArgs e)
        {
            this.LoadChartSalary();
        }

        private void InitComponent()
        {
            this.dtFromDate.EditValue = DateAndTime.DateAdd(DateInterval.Month, -2.0, this.clsAllOption.MonthDefault);
            this.dtToDate.EditValue = DateAndTime.DateAdd(DateInterval.Month, 0.0, this.clsAllOption.MonthDefault);
        }

        private void InitializeComponent()
        {
            SideBySideBarSeriesLabel label = new SideBySideBarSeriesLabel();
            this.panelControl3 = new PanelControl();
            this.lbPrintAge = new LinkLabel();
            this.chartSalary = new ChartControl();
            this.panelControl1 = new PanelControl();
            this.dtToDate = new TimeEdit();
            this.dtFromDate = new TimeEdit();
            this.labelControl2 = new LabelControl();
            this.labelControl1 = new LabelControl();
            this.llRefresh = new LinkLabel();
            this.panelControl3.BeginInit();
            this.panelControl3.SuspendLayout();
            this.chartSalary.BeginInit();
            ((ISupportInitialize) label).BeginInit();
            this.panelControl1.BeginInit();
            this.panelControl1.SuspendLayout();
            this.dtToDate.Properties.BeginInit();
            this.dtFromDate.Properties.BeginInit();
            base.SuspendLayout();
            this.panelControl3.BorderStyle = BorderStyles.NoBorder;
            this.panelControl3.Controls.Add(this.llRefresh);
            this.panelControl3.Controls.Add(this.lbPrintAge);
            this.panelControl3.Dock = DockStyle.Bottom;
            this.panelControl3.Location = new Point(0, 370);
            this.panelControl3.Name = "panelControl3";
            this.panelControl3.Size = new Size(0x250, 0x18);
            this.panelControl3.TabIndex = 7;
            this.lbPrintAge.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.lbPrintAge.AutoSize = true;
            this.lbPrintAge.Location = new Point(5, 5);
            this.lbPrintAge.Name = "lbPrintAge";
            this.lbPrintAge.Size = new Size(0x37, 13);
            this.lbPrintAge.TabIndex = 1;
            this.lbPrintAge.TabStop = true;
            this.lbPrintAge.Text = "In biểu đồ";
            this.lbPrintAge.LinkClicked += new LinkLabelLinkClickedEventHandler(this.ChartPrint_LinkClicked);
            this.chartSalary.BorderOptions.Visible = false;
            this.chartSalary.Dock = DockStyle.Fill;
            this.chartSalary.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center;
            this.chartSalary.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside;
            this.chartSalary.Legend.Direction = LegendDirection.LeftToRight;
            this.chartSalary.Location = new Point(0, 0x1f);
            this.chartSalary.Name = "chartSalary";
            this.chartSalary.OptionsPrint.SizeMode = PrintSizeMode.Zoom;
            this.chartSalary.RuntimeSelection = true;
            this.chartSalary.SeriesSerializable = new Series[0];
            label.LineVisible = true;
            this.chartSalary.SeriesTemplate.Label = label;
            this.chartSalary.Size = new Size(0x250, 0x153);
            this.chartSalary.TabIndex = 8;
            this.panelControl1.BorderStyle = BorderStyles.NoBorder;
            this.panelControl1.Controls.Add(this.dtToDate);
            this.panelControl1.Controls.Add(this.dtFromDate);
            this.panelControl1.Controls.Add(this.labelControl2);
            this.panelControl1.Controls.Add(this.labelControl1);
            this.panelControl1.Dock = DockStyle.Top;
            this.panelControl1.Location = new Point(0, 0);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new Size(0x250, 0x1f);
            this.panelControl1.TabIndex = 9;
            this.dtToDate.EditValue = new System.DateTime(0x7dc, 12, 0x12, 0, 0, 0, 0);
            this.dtToDate.Location = new Point(0xc4, 5);
            this.dtToDate.Name = "dtToDate";
            this.dtToDate.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.dtToDate.Properties.Appearance.Options.UseFont = true;
            this.dtToDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtToDate.Properties.DisplayFormat.FormatString = "MM/yyyy";
            this.dtToDate.Properties.EditFormat.FormatString = "MM/yyyy";
            this.dtToDate.Properties.Mask.EditMask = "MM/yyyy";
            this.dtToDate.Properties.Mask.UseMaskAsDisplayFormat = true;
            this.dtToDate.Size = new Size(0x4b, 20);
            this.dtToDate.TabIndex = 6;
            this.dtToDate.EditValueChanged += new EventHandler(this.dtToDate_EditValueChanged);
            this.dtFromDate.EditValue = new System.DateTime(0x7dc, 12, 0x12, 0, 0, 0, 0);
            this.dtFromDate.Location = new Point(0x3a, 5);
            this.dtFromDate.Name = "dtFromDate";
            this.dtFromDate.Properties.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.dtFromDate.Properties.Appearance.Options.UseFont = true;
            this.dtFromDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtFromDate.Properties.DisplayFormat.FormatString = "MM/yyyy";
            this.dtFromDate.Properties.EditFormat.FormatString = "MM/yyyy";
            this.dtFromDate.Properties.Mask.EditMask = "MM/yyyy";
            this.dtFromDate.Properties.Mask.UseMaskAsDisplayFormat = true;
            this.dtFromDate.Size = new Size(0x4b, 20);
            this.dtFromDate.TabIndex = 5;
            this.dtFromDate.EditValueChanged += new EventHandler(this.dtFromDate_EditValueChanged);
            this.labelControl2.Location = new Point(0x8b, 8);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x33, 13);
            this.labelControl2.TabIndex = 3;
            this.labelControl2.Text = "Đến th\x00e1ng";
            this.labelControl1.Location = new Point(8, 8);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x2c, 13);
            this.labelControl1.TabIndex = 1;
            this.labelControl1.Text = "Từ th\x00e1ng";
            this.llRefresh.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.llRefresh.AutoSize = true;
            this.llRefresh.Location = new Point(0x4c, 5);
            this.llRefresh.Name = "llRefresh";
            this.llRefresh.Size = new Size(0x27, 13);
            this.llRefresh.TabIndex = 1;
            this.llRefresh.TabStop = true;
            this.llRefresh.Text = "Nạp lại";
            this.llRefresh.LinkClicked += new LinkLabelLinkClickedEventHandler(this.llRefresh_LinkClicked);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.chartSalary);
            base.Controls.Add(this.panelControl1);
            base.Controls.Add(this.panelControl3);
            base.Name = "xucChartSalary";
            base.Size = new Size(0x250, 0x18a);
            this.panelControl3.EndInit();
            this.panelControl3.ResumeLayout(false);
            this.panelControl3.PerformLayout();
            ((ISupportInitialize) label).EndInit();
            this.chartSalary.EndInit();
            this.panelControl1.EndInit();
            this.panelControl1.ResumeLayout(false);
            this.panelControl1.PerformLayout();
            this.dtToDate.Properties.EndInit();
            this.dtFromDate.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void llRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.LoadChartSalary();
        }

        public void LoadChartSalary()
        {
            int month = System.DateTime.Parse(this.dtFromDate.EditValue.ToString()).Month;
            int year = System.DateTime.Parse(this.dtFromDate.EditValue.ToString()).Year;
            int num3 = System.DateTime.Parse(this.dtToDate.EditValue.ToString()).Month;
            int num4 = System.DateTime.Parse(this.dtToDate.EditValue.ToString()).Year;
            HRM_SALARY hrm_salary = new HRM_SALARY();
            this.chartSalary.Series.Clear();
            Series series = new Series("Tiền lương thực l\x00e3nh", ViewType.Area);
            Series series2 = new Series("Đ\x00e3 thanh to\x00e1n", ViewType.Area);
            Series series3 = new Series("C\x00f2n nợ lại", ViewType.Area);
        Label_0247:;
            if (((year == num4) && (month <= num3)) || (year < num4))
            {
                DataTable table = hrm_salary.CreateChart(MyLogin.Level, MyLogin.Code, month, year);
                decimal num5 = 0M;
                decimal num6 = 0M;
                decimal num7 = 0M;
                try
                {
                    num5 = decimal.Parse(table.Rows[0]["Salary"].ToString());
                    num6 = decimal.Parse(table.Rows[0]["SalaryPay"].ToString());
                    num7 = decimal.Parse(table.Rows[0]["SalaryDebt"].ToString());
                }
                catch
                {
                }
                SeriesPoint point = new SeriesPoint(month + "/" + year, new object[] { num5 });
                SeriesPoint point2 = new SeriesPoint(month + "/" + year, new object[] { num6 });
                SeriesPoint point3 = new SeriesPoint(month + "/" + year, new object[] { num7 });
                series.Points.Add(point);
                series2.Points.Add(point2);
                series3.Points.Add(point3);
                if (month == 12)
                {
                    year++;
                    month = 1;
                }
                else
                {
                    month++;
                }
                goto Label_0247;
            }
            this.chartSalary.Series.Add(series);
            this.chartSalary.Series.Add(series2);
            this.chartSalary.Series.Add(series3);
            series.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            series2.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            series3.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;
            this.chartSalary.RuntimeSeriesSelectionMode = SeriesSelectionMode.Series;
        }
    }
}

